<?php 
/*
$_GET["listid"];
$_GET["page"];
$_GET["pagesize"];
*/
require("errorhandle.php");

require("phpconnect.php");

$perNumber=$_GET["pagesize"]; //每页显示的记录数
$page=$_GET['page']; //获得当前的页面值
$listid=$_GET["listid"];
//echo"SELECT count(*) FROM article where pid=" . $_GET["listid"] . " and shelves=0";
//return;
if(!isset($perNumber))
{
    $perNumber=20;
}

$count=mysql_query("SELECT count(*) FROM article where pid=" . $listid . " and shelves=0"); //获得记录总数
if(!$count)
{
    mysql_close($con);
    errorHandle($queryarticlelcounterror);
	return;
}
$rs=mysql_fetch_array($count); 
$totalNumber=$rs[0];
$totalPage=ceil($totalNumber/$perNumber); //计算出总页数
if (!isset($page)) //如果没有值,则赋值1
{
    $page=1;
} 
$startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
//$result=mysql_query("select * from user limit $startCount,$perNumber"); //根据前面的计算出开始的
$result = mysql_query("SELECT id,title,pubtime,paytype FROM article where pid=" . $listid . " and shelves=0 order by pubtime desc limit $startCount,$perNumber");
if(!$result)
{
    mysql_close($con);
    errorHandle($queryarticlelerror);
	return;
}

$articlelist=new articlelist;

$index=0;
while($row = mysql_fetch_array($result))
{
    $article  = new article;
	$article->articleid=$row['id'];
	$article->title=$row['title'];
	$tmptimei = strpos($row['pubtime']," ");
	if (!isset($tmptimei)||$tmptimei<=0) //如果没有值,则赋值1
    {
	    $article->time=$row['pubtime'];
    }
	else
	{
	    $article->time=substr($row['pubtime'],0,$tmptimei);
	}
	$article->paytype=$row['paytype'];
	
    $articlelist->articlelist[$index]=$article;
	
   //  echo $row['id'] . " " . $row['title'] . " " . $row['pubtime'];
    //echo "<br />";
    $index++;
}

$article_json = json_encode($articlelist);
echo $article_json;
mysql_close($con);


//文章列表
class articlelist 
{
	public $articlelist=array();
}
//文章项
class article 
{
	public $title;
	public $articleid;
	public $time;
	public $paytype;
}

?>